package com.lsa.skienna.challenge.chap9.the110901_Bicoloring;

import java.util.AbstractMap;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class OrderedPair2Judge {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("[{},]|\\s");
		Set<Integer> vertices = new TreeSet<Integer>();
		Set<Map.Entry<Integer, Integer>> edges = new TreeSet<Map.Entry<Integer, Integer>>(
				new Comparator<Map.Entry<Integer, Integer>>() {
					@Override
					public int compare(Entry<Integer, Integer> o1,
							Entry<Integer, Integer> o2) {
						return toStr(o1).compareTo(toStr(o2));
					}
					String toStr(Entry<Integer, Integer> o) {
						return o.getKey() + " " + o.getValue();
					}
				});
		

		int[] edgeArr = new int[2];
		int cur = 0;
		while(sc.hasNext()) {
			String tok = sc.next();
			if (tok.trim().length() == 0) continue;
			if (tok.contains("!")) break;
			edgeArr[cur++] = Integer.parseInt(tok) - 1; 
			if (cur == 2) {
				vertices.add(edgeArr[0]);
				vertices.add(edgeArr[1]);
				edges.add(new AbstractMap.SimpleEntry<Integer,Integer>(edgeArr[0], edgeArr[1]));
				cur = 0;
			}
		}	
		
		System.out.println(vertices.size());
		System.out.println(edges.size());
		
		for (Map.Entry<Integer, Integer> edge : edges) {
			System.out.println(String.format("%s %s", edge.getKey(), edge.getValue()));
		}
	}
}
/*
 * {{2, 1}, {3, 2}, {4, 3}, {6, 5}, {7, 6}, {8, 7}, {10, 9}, {11, 
  10}, {12, 11}, {14, 13}, {15, 14}, {16, 15}, {18, 17}, {19, 
  18}, {20, 19}, {22, 21}, {23, 22}, {24, 23}, {5, 1}, {6, 2}, {7, 
  3}, {8, 4}, {9, 5}, {10, 6}, {11, 7}, {12, 8}, {13, 9}, {14, 
  10}, {15, 11}, {16, 12}, {17, 13}, {18, 14}, {19, 15}, {20, 
  16}, {21, 17}, {22, 18}, {23, 19}, {24, 20}, {1, 2}, {2, 3}, {3, 
  4}, {5, 6}, {6, 7}, {7, 8}, {9, 10}, {10, 11}, {11, 12}, {13, 
  14}, {14, 15}, {15, 16}, {17, 18}, {18, 19}, {19, 20}, {21, 
  22}, {22, 23}, {23, 24}, {1, 5}, {2, 6}, {3, 7}, {4, 8}, {5, 9}, {6,
   10}, {7, 11}, {8, 12}, {9, 13}, {10, 14}, {11, 15}, {12, 16}, {13, 
  17}, {14, 18}, {15, 19}, {16, 20}, {17, 21}, {18, 22}, {19, 
  23}, {20, 24}}*/
